﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Data.Linq.Mapping;

namespace QuickManager.Code
{
    public static class DBModelExtend
    {
        public static void ToUpdateModel<T>(this T oldT, T newT)
            where T : class
        {
            Type type = typeof(T);
            PropertyInfo[] propteries = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo p in propteries)
            {
                if (p.GetCustomAttributes(typeof(ColumnAttribute), false).FirstOrDefault(m => (m as ColumnAttribute).IsPrimaryKey == true) == null)
                {
                    p.SetValue(oldT, p.GetValue(newT, null), null);
                }
            }
        }
    }
}
